package cn.yujiago.activiti.controller;

import cn.yujiago.activiti.dto.LeaveBillVO;
import cn.yujiago.activiti.dto.ResponseEntity;
import cn.yujiago.activiti.service.QJLCService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/qjlc")
public class QJLCController {

    @Autowired
    private QJLCService qjlcService;

    // 启动流程实例
    @PostMapping("/startProcessInstance")
    @ResponseBody
    public ResponseEntity startProcessInstance(LeaveBillVO leaveBillVO){
        return qjlcService.startProcessInstance(leaveBillVO);
    }

    /**
     * 审批页面
     * 1、请假单的信息（请假原因，请假天数，请假人等）
     * 2、当前任务完成后的流程连线名称
     * 3、当前任务的历史审批意见
     */
    @GetMapping("/auditByTaskId")
    @ResponseBody
    public ResponseEntity auditByTaskId(@RequestParam("taskId") String taskId) {
        ResponseEntity result = qjlcService.auditByTaskId(taskId);
        return result;
    }

    // 办理任务
    @PostMapping("/submitTask")
    @ResponseBody
    public ResponseEntity submitTask(LeaveBillVO leaveBillVO) {
        ResponseEntity result = qjlcService.saveSubmitTask(leaveBillVO);
        return result;
    }

    // 通过实例ID和业务ID获取详情
    @GetMapping("/detailByPIIdAndLBId")
    @ResponseBody
    public ResponseEntity detailByProcessInstanceId(@RequestParam("processInstanceId") String processInstanceId, @RequestParam("leaveBillId") String leaveBillId) {
        ResponseEntity result = qjlcService.detailByPIIdAndLBId(processInstanceId, leaveBillId);
        return result;
    }
}
